package es.ibm.santillana.mdm.stringenumerationrule;

import java.util.List;

import com.ibm.pim.collaboration.CollaborationItem;
import com.ibm.pim.collaboration.CollaborationStep;
import com.ibm.pim.extensionpoints.CategoryStringEnumerationValueRuleFunctionArguments;
import com.ibm.pim.extensionpoints.CollaborationCategoryStringEnumerationValueRuleFunctionArguments;
import com.ibm.pim.extensionpoints.CollaborationItemStringEnumerationValueRuleFunctionArguments;
import com.ibm.pim.extensionpoints.ItemStringEnumerationValueRuleFunctionArguments;
import com.ibm.pim.extensionpoints.StringEnumerationValueRuleFunction;
import com.ibm.pim.utils.Logger;

import es.ibm.santillana.mdm.common.bussinesmodel.ConfigModel;
import es.ibm.santillana.mdm.common.util.ConstSantillana;
import es.ibm.santillana.mdm.common.util.SantillanaLogger;

public class SociedadRules implements StringEnumerationValueRuleFunction {

	//script_execution_mode=java_api="japi:///public_html/clases:es.elcorteingles.n0141.apl2WP.dvd.process.batch.T2WPDN.paralelizado.T2WPDN_DVD_IMG_DOC2.class"
	
	@Override
	public String[] rule(ItemStringEnumerationValueRuleFunctionArguments arg0) {
		
		
		String[] valores = ConfigModel.getSociedades();
		
		return valores;
	}

	@Override
	public String[] rule(
			CategoryStringEnumerationValueRuleFunctionArguments arg0) {
		return null;
	}

	@Override
	public String[] rule(
			CollaborationItemStringEnumerationValueRuleFunctionArguments arg0) {
		
		Logger log = SantillanaLogger.getLogger();
		String[] valores = null;
		
		String colAreaName = arg0.getCollaborationItem().getCollaborationArea().getName();
		log.logInfo("colAreaName "+colAreaName);
		String countryCode = ConfigModel.getCountryCodeFromColArea(colAreaName);
		log.logInfo("countryCode "+countryCode);
		
		List<CollaborationStep> stpList = arg0.getCollaborationItem().getSteps();
		
		if (stpList!=null){
			if (stpList.size() == 0){
				valores = ConfigModel.getSociedadesByCountry(countryCode);
			}else{ 
				String stpName = stpList.get(0).getName();
				log.logInfo("stpName "+stpName);
				if (stpName.equals(ConstSantillana.STEP_CATALOGAR)){
					valores = ConfigModel.getSociedadesByCountry(countryCode);
				}else{
					valores = ConfigModel.getEmpresasEditoras(ConstSantillana.CATALOGO_SOCIEDADES);
				}
			}
		}else{
			log.logInfo("step nulo ");
			valores = ConfigModel.getSociedadesByCountry(countryCode);
		}
		
		return valores;
	}

	@Override
	public String[] rule(
			CollaborationCategoryStringEnumerationValueRuleFunctionArguments arg0) {
		
		
		
		return null;
	}
	
	
}
